<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>选择产品挂靠公司列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div class="searchArea">
			<form id="searchBar">
				<div class="fieldset1 clearFix">
					<div class="fieldBox">
						<div class="label">挂靠公司名称</div>
						<div class="field">
							<input name="lnkCompNm" id="lnkCompNm" type="text"
								class="ui-textbox" value="">
						</div>
					</div>
					<div class="fieldBox">
                            <div class="label">姓名</div>
                            <div class="field">
                                <input name="rlNm" id="rlNm" type="text"
                                       class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">证件号</div>
                            <div class="field">
                                <input name="certNo" id="certNo" type="text"
                                       class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">手机号</div>
                            <div class="field">
                                <input name="rlTel" id="rlTel" type="text"
                                       class="ui-textbox" value="">
                            </div>
                        </div>
					<%--  <div class="fieldBox">
                <div class="label">审核状态</div>
                <div class="field">
                     <select name="audStsCd"  id="audStsCd"   data-value="">
                     <option value="  "   selected="selected">--请选择--</option>
                     <c:forEach items="${keyValueList}" var="item">
                     	<option value="${item.key}">${item.value }</option>
                     </c:forEach>
				     </select>
                </div>
            </div> --%>

					<div class="formBtns notRight">
						<span id="searchBtn" class="sq-button-round">查询</span> <span
							id="clearBtn" onclick="clearBtn();" class="sq-button-round">清空</span>
					</div>
				</div>
			</form>

		</div>
		<div id="ligergrid1" class="sq-grid"></div>
	</div>

	<script type="text/javascript">
	var grid = null;
	var dtlId = '${dtlId}';
	var prdDtlIds = '${ids}';
	var prjTypCd = '${prjTypCd}';
	var prjId = '${prjId}';
	var vehNo = '${vehNo}';
	var splId = '${splId}';
	var prjPrdChangeFlag = '${prjPrdChangeFlag}';
	var audStsCdList = new Array();
	audStsCdList.push(CommonConstant.C_AUD_PASS_CODE);
    audStsCdList.push(CommonConstant.C_AUD_ADNWAY_CODE);
    audStsCdList.push(CommonConstant.C_AUD_CHANGEADNWAY_CODE);
	if(splId != null && splId != ''){
		audStsCdList.push(CommonConstant.C_AUD_NO_PASS_CODE);
	}else{
		audStsCdList.push(CommonConstant.C_AUD_REJECT_CODE);
	}
	var audStsCdListArr = JSON.stringify(audStsCdList);
	$(function () {
		var urlAdr = '<%=path%>/project/prjlnkcomp/initList.do?audStsCdList='+audStsCdListArr+'&isQueryExpDt=0'+'&isBlackList=0';
		if(ProjectConstant.PRJ_TYP_CD_CDDYWUL == prjTypCd || ProjectConstant.PRJ_TYP_CD_ESCJYD == prjTypCd || ProjectConstant.PRJ_TYP_CD_OWNJYD == prjTypCd){
			urlAdr = '<%=path%>/project/prjlnkcomp/initList.do?audStsCdList='+audStsCdListArr+'&isQueryExpDt=0'+'&isBlackList=0'+'&prjId='+ prjId +'&vehNo='+ vehNo +'&prjTypCd='+ prjTypCd ;
		}
		if(splId != null && splId != ''){
			urlAdr = '<%=path%>/project/prjlnkcomp/initListNew.do?audStsCdList='+audStsCdListArr+'&isQueryExpDt=0'+'&isBlackList=0'+'&prjId='+ prjId +'&vehNo='+ vehNo +'&prjTypCd='+ prjTypCd +'&splId='+splId;
		}
	    $("#ligergrid1").ligerGrid({
	    	url: urlAdr,
	    	method : 'get',
	        columns: [
				{ display: '提示', name: 'lnkCompMsg', minWidth: 150},
	            { display: '公司名称', name: 'lnkCompNm', minWidth: 120,
	            	 render: function (rowdata, rowindex, value){
		                    var h='';
			                    if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
			                    	h+='<i class="ico_flasher"></i>';
			                    }
		                        h+=rowdata.lnkCompNm;
		                    return h;
		                }},
	            { display: '成立日期', name: 'regDt', minWidth: 140 , render:renderDate,enabledSort:true},
	            { display: '企业类型', name: 'compTyp', minWidth: 60},
	            { display: '法人代表', name: 'corpRep', minWidth: 140 },
	            { display: '联系人', name: 'lnkNm', minWidth: 140 },
	            { display: '是否黑名单', name: 'isBlackList', minWidth: 140 ,render:function(rowdata){
	                if(rowdata.isBlackList=='1'){
	                    return "黑名单";
                    }
                    }},
	            {
	                display: '操作',
	                isSort: false,
	                width: 100,
	                render: function (rowdata, rowindex, value){
	                    var h='<a class="sq-button-hasicon" href="javascript:chooseLnkComp(';
	                        h+="'"+rowdata.id+"',";
	                        h+="'"+rowdata.lnkCompNm+"',";
							h+="'"+rowdata.lnkCompMsg+"',";
							h+="'"+rowdata.lnkStartLvl+"',";
	                       // h+="'"+rowdata.lnkCompNm+"',";
	                        h+="'"+rowdata.isBlackList+"'";
	                        h+=')"><i class="sqBtnIco_3"></i>选择</a>';
						if(rowdata.audStsCd == '3'){
							h = '';
						}
	                    return h;
	                }
	            }
	        ],
			<c:if test="${splId == null || splId == ''}">
			pageSize:10,
			</c:if>
			<c:if test="${splId != null && splId != ''}">
			pageSize:50,
			</c:if>
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        //isScroll: false,
	        checkbox:true,
	        rownumbers:true
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	//查询
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         data["lnkCompNm"] = $("#lnkCompNm").val();
	         data["audStsCd"] = $("#audStsCd").val();
	         
	         data["rlNm"] = $("#rlNm").val();
	         data["certNo"] = $("#certNo").val();
	         data["rlTel"] = $("#rlTel").val();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	});
	
	//格式化时间
	function renderDate(rowdata, index, value) {
		var dateStr = "";
		if (null != value) {
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	//选择
	function chooseLnkComp(lnkCompId,lnkCompNm,lnkCompMsg,lnkStartLvl){//compId
		if(lnkCompId){
			//更新产品的挂靠公司信息
			var params = {};
			params.lnkCmpNm = lnkCompNm;//挂靠公司名称
			params.prdDtlIds =prdDtlIds;//产品id
			params.lnkCompId = lnkCompId;//挂靠公司id
			if(lnkCompMsg != 'null'){
				params.lnkCompMsg = lnkCompMsg;//挂靠公司提示信息
			}else{
				params.lnkCompMsg = '';
			}
			if(lnkStartLvl != 'null'){
				params.lnkStartLvl = lnkStartLvl;//挂靠公司星级
			}else{
				params.lnkStartLvl = '';
			}
			params.prjId = prjId;
			params.vehNo =vehNo;
			params.splId =splId;
            $.ajax({
                type: 'post',
                dataType:'json',
                data:{
                    lnkCompId: lnkCompId,
                    prjTypCd: prjTypCd
                },
                url: '<%=path%>/project/prjprddtl/checkLnkIsChooseUsedCar.do',
                success : function(msg) {
                    if (msg.success == 0) {
                        top.$.ligerDialog.SQalert({content : msg.info, SQ_type : "error"});
                    } else {
                    	console.log(prdDtlIds);
                    	console.log('""');
                        //根据查询的id 不同做的判断  tiansainan
                        if(prdDtlIds == ""){//统一保存
                            //将子页面的值赋到父页面（modifyPrdDtlCarPrdInfo方法）
                            parent.window.document.getElementById("lnkCompNm").value=lnkCompNm;//挂靠公司名称
                            if(!lnkCompNm){
                                lnkCompNm = "";
                            }
                            parent.window.document.getElementById("lnkCompId").value=lnkCompId;//挂靠公司ID
                            if(!lnkCompId){
                                lnkCompId = "";
                            }

							parent.window.document.getElementById("lnkCompMsg").value=params.lnkCompMsg;//挂靠公司提示信息
							if(!lnkCompMsg){
								lnkCompMsg = "";
							}
							parent.window.document.getElementById("lnkStartLvl").value=params.lnkStartLvl;//挂靠公司星级
							if(!lnkStartLvl){
								lnkStartLvl = "";
							}

                            parent.$.ligerDialog.close();
                            parent.$(".l-dialog,.l-window-mask").css("display","none");
                        } else if (dtlId == "") {
							params.lnkCompType = "1";//挂靠公司类型 公户
                            $.ajax({
                                type: 'post',
                                dataType:'json',
                                data:params,
                                url: '<%=path%>/project/prjprddtl/modifyPrdLnkComp.do',
                                success : function(msg) {
                                    if (msg.success == 1) {
										if (prjPrdChangeFlag && prjPrdChangeFlag == 'true') {
											parent.location.reload();
										} else {
											parent.grid.reload();
										}
                                        parent.$.ligerDialog.close();
                                        parent.$(".l-dialog,.l-window-mask").css("display", "none");
                                    } else {
                                        top.$.ligerDialog.SQalert({content : msg.info, SQ_type : "error"});
                                    }
                                }
                            });
                        }
                    }
                }
            });
        }
    }
	//清空
	function clearBtn() {
		var form = new liger.get("searchBar");
		form.setData({
            lnkCompNm: " ",
            rlNm: " ",
            rlTel: " ",
            certNo: " ",
		});
	}
	</script>

</body>
</html>